home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / NeoPersist 3.0.8 folder / NeoIncludes / CNeoDatabase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-13  |  7.2 KB  |  185 lines  |  [TEXT/MMCC]

  1.  /************************************************************
  2.  *
  3.  *    Created: Friday, March 8, 1991 11:24:46 AM
  4.  *    CNeoDatabase.h
  5.  *    C++ class implementation for the NeoAccess database class
  6.  *
  7.  *
  8.  *    Copyright © Neologic Systems 1992-1994. All Rights Reserved.
  9.  *    All rights reserved
  10.  *
  11.  *
  12.  * The CNeoDatabase class is, in effect, an area manager. The area it manages is a
  13.  * string of bytes that can be added to at the end. Access to the area however
  14.  * is slower than accessing main memory. Information in the area can only be
  15.  * accessed by allocating space in main memory. This main memory space needs
  16.  * to be used as a cache of the database's contents.
  17.  *
  18.  ***********************************************************/
  19. #pragma once            /* Include this file only once */
  20. #ifndef __CNeoDatabase__
  21. #define __CNeoDatabase__ 1
  22.  
  23. #include "NeoTypes.h"
  24. #include CNeoDatabaseBaseH
  25.  
  26. class CNeoMetaClass;
  27. class CNeoDatabase;
  28. class CNeoPersist;
  29. class CNeoIndexIterator;
  30. class CNeoPeer;
  31. class CNeoContainerStream;
  32. class CNeoTransaction;
  33.  
  34. enum {kNeoUniqueIDBlockSize            = 1000};
  35. enum {kNeoDatabaseCurrVersion        = 0};                        // current NeoAccess database version
  36. enum {kNeoDatabaseHeadSpace            = (0x0100 + kNeoMinMark)};    // file space allocated for file header
  37. enum {kNeoDatabaseQuantum            = 8};                        // file space allocations are rounded to this quantum
  38. const long kNeoPurgeQuantum            = 0x10000;                    // object cache purges are at least this quantum
  39.  
  40. #define NeoDatabaseQuantumSpace(n)    (((long)((n) + 7))&0x7FFFFFF8)    // file space to really allocate
  41. #define NeoPurgeQuantumSpace(n)        ((n) > kNeoPurgeQuantum ? (n) : kNeoPurgeQuantum)
  42.  
  43.  
  44. class CNeoDatabase : public CNeoDatabaseBase
  45. {
  46. public:
  47.                         /** Instance Methods **/
  48.                         CNeoDatabase(void);
  49.     void                INeoDatabase(void);
  50.     virtual                ~CNeoDatabase(void);
  51.  
  52.     virtual OSErr        close(void);
  53.     virtual OSErr        create(void);
  54.     virtual void        flush(const Boolean aEntireDatabase);
  55.     virtual OSErr        open(const NeoPerms aPerms);
  56.     virtual void        reset(void);
  57.  
  58.                         /** Access Methods **/
  59.     virtual Boolean        existsOnDisk(void) const;
  60.     static CNeoDatabase *
  61.                         GetCurrentDatabase(void) {return gNeoDatabase;}
  62.     long                getLength(void) const;
  63.     NeoMark                getMark(void) const;
  64.     virtual void        getName(CNeoString &aName) const;
  65.     virtual void        getPathName(CNeoString &aName) const;
  66.     CNeoContainerStream *
  67.                         getStream(const Boolean aStream = FALSE);
  68.     virtual NeoID        getUniqueID(void);
  69.     NeoID                getUniqueIDBlock(const long aCount);
  70.     long                getVersion(void) const {return fVersion;}
  71.     virtual Boolean        isDirty(void) const;
  72.     Boolean                isOpen(void) const;
  73.     static void            SetCurrentDatabase(CNeoDatabase *aDatabase);
  74.     void                setDirty(const Boolean aState = TRUE) {fDirty = aState;}
  75.     void                setFileSpec(const NeoFileSpec &aFileSpec);
  76.     virtual void        setLength(const long aLength);
  77.     virtual void        setMark(const NeoMark aMark);
  78.     void                setStream(CNeoContainerStream *aStream);
  79.     void                setVersion(const long aVersion);
  80.  
  81.                         /** Macintosh Methods **/
  82.     virtual OSType        getCreator(void) const;
  83.     virtual OSType        getType(void) const;
  84.     virtual void        setCreator(const OSType aCreator);
  85.     virtual void        setType(const OSType aType);
  86.  
  87.                         /** I/O Methods **/
  88.     virtual void        commit(const Boolean aCompress = FALSE, const Boolean aRemotely = FALSE, CNeoTransaction *aTransaction = nil);
  89.  
  90.                         /** Object List Methods **/
  91.     virtual void        addObject(CNeoPersist *aObject);
  92.     void                enableTempRemoval(const Boolean aEnable = TRUE) {fRemoveTemps = aEnable;}
  93.     virtual void *        findObject(const NeoID aClassID, CNeoSelect *aKey, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil, const NeoLockType aLock = kNeoDefaultLock);
  94.     CNeoIndexIterator *    getIterator(const NeoID aClassID, CNeoSelect *aKey = nil, const Boolean aDeeply = FALSE, const Boolean aForward = TRUE);
  95.     virtual void        removeObject(CNeoPersist *aObject);
  96.     virtual void        removeTempObjects(const Boolean aAll);
  97.  
  98.                         /** Free List Methods **/
  99.     void                freeSpace(const NeoMark aMark, const long aLength);
  100.     Boolean                getFastAllocation(void) const {return (Boolean)(fFastAlloc > 0);}
  101.     NeoMark                getSpace(const long aLength);
  102.     NeoMark                getSpaceBefore(const long aLength, const NeoMark aMark);
  103.     void                setFastAllocation(const Boolean aFast = TRUE);
  104.  
  105.                         /** Class List Methods **/
  106.     virtual Boolean        addClass(CNeoMetaClass *aMeta);
  107.     virtual long        getClassCount(void);
  108.     virtual long        getObjectCount(const NeoID aClassID, const Boolean aDeeply);
  109.     virtual void        markClassTemporary(const NeoID aID, const Boolean aTemp);
  110.  
  111.                         /** Iteration Methods **/
  112.     void *                doUntilClass(const NeoID aClassID, const Boolean aDeeply, NeoTestClassFunc aFunc = nil, void *aParam = nil);
  113.     void *                doUntilObject(CNeoPersist *aStart, const NeoID aClassID, const short aWhich, const Boolean aDeeply, NeoTestFunc1 aFunc = nil, void *aParam = nil);
  114.  
  115.     NeoVersion            getVersionUpdateType(void) const {return fVersionUpdateType;}
  116.     void                setUpdateType(const NeoVersion aType) {fVersionUpdateType = aType;}
  117.  
  118.                         /** Concurrency Methods **/
  119.     void                lock(const NeoRefType /* aType */, long /* aMilliSeconds */ = kNeoWaitForever) {}
  120.     void                unlock(const NeoRefType /* aType */) {}
  121.  
  122.                         /** MetaClass Creation Methods **/
  123.     static void            CreateDefaultMetaclasses(void);
  124.  
  125.                         /** Purge Methods **/
  126.     virtual Boolean        purge(NeoSize &aNeeded);
  127.     static Boolean        PurgeCache(long aNeeded);
  128.  
  129.                         /** Instance Variables **/
  130. protected:
  131.     Boolean                fRemoveTemps;        // should temporary objects be removed when the database is opened?
  132.     Boolean                fDirty;                // has file header changed since last written to database?
  133.     Boolean                fCommitting;        // is the database being committed?
  134. public:
  135.     Boolean                fEmpty;                // should the length be set ot zero on open?
  136.     NeoFormat            fFileFormat;        // NeoAccess file format used in writing this file
  137.  
  138. protected:
  139.     long                fFastAlloc;            // need very fast file space allocation if > 0
  140.     CNeoNode *            fFreeList;            // a handle to the first free list node in memory
  141.     CNeoNode *            fClassList;            // a handle to the first class list node in memory
  142.     long                fLength;            // length of database on disk before stream is open
  143.  
  144.     // File header data members
  145.     long                fVersion;            // database version number
  146.     NeoMark                fFreeMark;            // a file mark of the first free list node in memory
  147.     NeoMark                fClassMark;            // a file mark of the first class list node in memory
  148.     long                fClassCount;        // number of classes defined in this database
  149.     NeoID                fID;                // next unique ID value of this database
  150.  
  151. public:
  152.     CNeoContainerStream *
  153.                         fNewStream;            // For use during save as operations
  154.     CNeoNode *            fNewIndice;            // index being added
  155.     NeoVersion            fVersionUpdateType;    // Defines how object version #s are updated when committed
  156.  
  157. protected:
  158.     CNeoContainerStream *
  159.                         fStream;
  160.  
  161. public:
  162.     static short        FPurgeLevel;        // what to purge
  163.     static long            FPurgeMin;            // minimum number of objects to purge at once
  164.     static long            FPurgeDelta;        // minimum number of objects before calling MaxBlock
  165.     static long            FPurgeCount;        // objects purged so far
  166. };
  167.  
  168. class CNeoIdleChore : public CNeoChore {
  169. public:
  170.                         /** Instance Methods **/
  171.     void                remove(void);
  172. };
  173.  
  174. class CNeoRemoveIdleChore : public CNeoChore {
  175. public:
  176.                         /** Instance Methods **/
  177.                         CNeoRemoveIdleChore(CNeoChore *aChore);
  178.  
  179.     virtual void        Perform(long *maxSleep);
  180.  
  181. protected:
  182.     CNeoChore *            fChore;
  183. };
  184. #endif
  185.